<?
require_once("base/BaseEventForm.php");
require_once("cms/event/om/Event.php");
require_once("cms/core/om/Image.php");

class EventForm extends BaseEventForm {

    private $log;
    private $language;

    public function __construct() {
        parent::__construct();
        $this->log =& LoggerManager::getLogger("EventForm");
        $this->getEventI18n()->setEvent(new Event());
        $this->getEventI18n()->getEvent()->setImageRelatedByImageId(new Image());
        $this->getEventI18n()->getEvent()->setImageRelatedByThumbnailId(new Image());
    }

    public function reset(ActionConfig $mapping, Request $request) {
        $this->language = $request->getContext()->getInitParameter(
            _Core::DEFAULT_LANGUAGE);
    }

    public function validate() {

        global $ALLOWABLE_IMAGES;

        $ALLOWABLE_IMAGES = array(
            "image/jpeg"=>"jpg",
            "image/pjpeg"=>"jpg",
            "image/gif"=>"gif",
            "image/png"=>"png"
        );

        $errors = parent::validate();

        if($this->getEventI18n()->getLanguageCode() == $this->language) {

            if(!is_null($this->getHour()) && "" != $this->getHour() && (is_null($this->getMinute()) || "" == $this->getMinute()))
                $errors->add("minute",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.minute", true)));

            if(!is_null($this->getMinute()) && "" != $this->getMinute() && (is_null($this->getHour()) || "" == $this->getHour()))
                $errors->add("hour",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.hour", true)));

            if(is_null($this->getDay()) || strlen($this->getDay()) == 0)
                $errors->add("day",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.day", true)));

            if(!is_null($this->getDay()) && strlen($this->getDay()) > 0 && strlen($this->getDay()) > 2)
                $errors->add("day",
                    new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.day", true),
                    new ActionMessage("2", false))));

            if(is_null($this->getMonth()) || strlen($this->getMonth()) == 0)
                $errors->add("month",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.month", true)));

            if(!is_null($this->getMonth()) && strlen($this->getMonth()) > 0 && strlen($this->getMonth()) > 2)
                $errors->add("month",
                    new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.month", true),
                    new ActionMessage("2", false))));

            if(is_null($this->getYear()) || strlen($this->getYear()) == 0)
                $errors->add("year",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.year", true)));

            if(!is_null($this->getYear()) && strlen($this->getYear()) > 0 && strlen($this->getYear()) > 4)
                $errors->add("year",
                    new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.year", true),
                    new ActionMessage("4", false))));

        }

        return $errors;
    }

}
?>